<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <title>评价</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="lib/layui-v2.5.5/css/layui.css" media="all">
    <link rel="stylesheet" href="css/layuimini.css">
    <link rel="stylesheet" href="css/public.css" media="all">
</head>
<body>
<div class="layuimini-container">
    <div class="layuimini-main">

        <fieldset class="table-search-fieldset">
            <legend>搜索信息</legend>
            <div style="margin: 10px 10px 10px 10px">
                <form id="customerSearchForm" class="layui-form layui-form-pane" action="">
                    <div class="layui-form-item">
                        <div class="layui-inline">
                            <label class="layui-form-label">客户名称</label>
                            <div class="layui-input-inline">
                                <input type="text" name="custName" autocomplete="off" class="layui-input" placeholder="输入客户名称">
                            </div>
                        </div>
                        <div class="layui-inline">
                        <label class="layui-form-label">评价对象</label>
                        <div class="layui-input-block">
                            <select id="toObject" name="toObject">
                                <option value="">--请选择--</option>
                                <option value="公司对客户">公司对客户</option>
                                <option value="客户对公司">客户对公司</option>
                            </select>
                        </div>
                    </div>
                        <div class="layui-inline">
                            <a class="layui-btn layui-btn-primary" lay-submit lay-filter="data-search-btn"><i
                                    class="layui-icon"></i> 搜 索</a>
                        </div>
                    </div>
                </form>
            </div>
        </fieldset>
        <script type="text/html" id="toolbarDemo">
            <div class="layui-btn-container">
                <!--<button class="layui-btn layui-btn-sm data-add-btn" > 添加客户 </button>-->
                <a href="javascript:;" class="layui-btn layui-btn-sm" data-iframe-tab="evaluationAdd.html"
                   data-title="添加评价" data-icon="fa fa-gears">添加评价</a>
            </div>
        </script>
        <table class="layui-hide" id="currentTableId" lay-filter="currentTableFilter"></table>

        <script type="text/html" id="currentTableBar">
            <a class="layui-btn layui-btn-xs data-count-edit" lay-event="edit">编辑</a>
            <a class="layui-btn layui-btn-xs layui-btn-danger data-count-delete" lay-event="delete">删除</a>
        </script>
    </div>
</div>
<script src="lib/layui-v2.5.5/layui.js" charset="utf-8"></script>
<!--tab跳转需要layuimini-->
<script src="js/lay-module/layuimini/layuimini.js" charset="utf-8"></script>
<script>
    layui.use(['form', 'table'], function () {
        var $ = layui.jquery,
            form = layui.form,
            table = layui.table,
            layuimini = layui.layuimini;
        <!--表格-->
        var tableIns = table.render({
            elem: '#currentTableId',
            url: 'evaluationList',
            method: 'post',
            toolbar: '#toolbarDemo',
            defaultToolbar: ['filter', 'exports', 'print', {
                title: '提示',
                layEvent: 'LAYTABLETIPS',
                icon: 'layui-icon-tips'
            }],
            request: {
                pageName: 'page', //页码的参数名称，默认：pageNum
                limitName: 'pageSize' //每页数据量的参数名，默认：pageSize
            },
            response: {
                statusName: 'code', //数据状态的字段名称，默认：code
                statusCode: 0, //成功的状态码，默认：0
                countName: 'count', //数据总数的字段名称，默认：count
                dataName: 'data' //数据列表的字段名称，默认：data
            },
            parseData: function (res) { //res 即为原始返回的数据
                //res.code=0;
                console.log(res);
                return {
                    "code": 0, //解析接口状态
                    "msg": res.msg, //解析提示文本
                    "count": res.total, //解析数据长度
                    "data": res.rows //解析数据列表
                };
            },
            cols: [
                [
                    {field: 'id', width: 90, title: '评价ID', sort: true},
                    {field: 'custId', width: 90, title: '客户ID', sort: true},
                    {field: 'custName', width: 150, title: '客户名称'},
                    {field: 'userId', width: 120, title: '负责人ID'},
                    {field: 'toObject', width: 150, title: '评价对象'},
                    {field: 'score', title: '评分', width: 90, sort: true},
                    {field: 'content', width: 150, title: '内容'},
                    {field: 'createtime', width: 150, title: '创建时间',templet : "<div>{{layui.util.toDateString(d.createtime, 'yyyy-MM-dd HH:mm')}}</div>",sort: true},
                    {title: '操作', minWidth: 50, templet: '#currentTableBar',  align: "center"}
                ]
            ],
            limits: [10, 20, 50, 100,500,1000],
            limit: 10,
            page: true
        });
        // 监听搜索操作
        form.on('submit(data-search-btn)', function (data) {
            var result = JSON.stringify(data.field);
            var text = JSON.parse(result);   //{text.custName,custSource。。。}
            //var custSource = $("#custSource option:selected").val();
            //var custIndustry = $("#custIndustry option:selected").val();
            //var custLevel = $("#custLevel option:selected").val();
            table.reload('currentTableId', {
                method: 'post'
                , where: text  //搜索框里的各个参数,通过这个实现搜索功能，table同一数据接口
                /*{
                    'custName': text.custName,
                    'custSource': custSource,
                    'custIndustry': custIndustry,
                    'custLevel':custLevel
                }*/
                , page: {
                    curr: 1
                }
            });
            layer.msg("数据正在加载", {icon: 6, time: 1000});
            /*layer.alert(result, {
                title: '最终的搜索信息'
            });*/
            return false;
        });
        table.on('tool(currentTableFilter)', function (obj) {
            var data = obj.data;
            console.log(data);
            if (obj.event === 'edit') {
                var index = layer.open({
                    title: '编辑评价',
                    type: 2,
                    shade: 0.2,
                    maxmin: true,
                    resize: false,
                    shadeClose: true,
                    area: ['75%', '80%'],
                    //content: ['customerAdd.html'+ '#custId'+'#custName'],
                    content: 'evaluationAdd.html?edit=1&id=' + data.id

                });
                /* $(window).on("resize", function () {
                     layer.full(index);
                 });*/
                return false;
            } else if (obj.event === 'delete') {
                console.log(data);
                layer.confirm('确定删除该评价吗', function (x) {
                    $.ajax({
                        type: "post",
                        data: {"id":data.id},
                        url: "deleteEvaluation",
                        success: function (data) {
                            //layer.alert();
                            layer.msg(data.msg, {
                                icon: 1,
                                time: 2000 //2秒关闭（如果不配置，默认是3秒）
                            }, function () {
                                //layer.closeAll();
                                obj.del();
                                layer.close(index);
                            })
                        }
                    });
                    return false;
                });
                /*layer.confirm('真的删除行么', function (index) {
                    obj.del();
                    layer.close(index);
                });*/
            }
        });

    })
</script>
</body>
</html>
